package net.xiduth.game.player.content.events.raiding;

import java.util.TimerTask;

import net.xiduth.cores.CoresManager;
import net.xiduth.game.World;
import net.xiduth.game.WorldTile;
import net.xiduth.game.npc.NPC;
import net.xiduth.game.player.Player;
import net.xiduth.utils.Logger;

/**
 * 
 * @author Jae <jae@xiduth.com>
 * 
 * @since <Oct 16, 2013>
 *
 */

public class LucienEvent {
	
	public static enum Delay {

		MUDSKIPPER(72000000), 
		LEGENDS(36000000),
		UNDERGROUND(18000000);

		public final int time;

		Delay(int time) {
			this.time = time;
		}

		public int getTime() {
			return time;
		}
	}
	
	public static final void killEvents() {
		Logger.log("Lucien", "All events killed.");
	}
	
	public static final void initLucienEvents() {
		Logger.log("Lucien", "Reading data...");
		initRefresh();
		initAll();
		Logger.log("Lucien", "Events initiated.");
	}

	public static final void initAll() {
		initSkipperPoint();
		initUnder();
		initLegends();
	}
	
	public static final void initSkipperPoint() {
		CoresManager.fastExecutor.schedule(new TimerTask() {
			@Override
			public void run() {
				try {
					initRefresh();
					World.sendWorldMessage(
							"<img=7><col=FF0000>News: A myserious figure has arrived at Mudskipper point!",
							false);
					World.sendWorldMessage(
							"<img=7><col=FF0000>Speak with General Khazard to join the battle!",
							false);
					World.spawnNPC(14256, new WorldTile(2996, 3117, 0), -1,
							true, true);
					Logger.log("Lucien", "Mudskipper: Raid initiated.");
				} catch (Throwable e) {
					Logger.handle(e);
				}
			}
		}, 0, Delay.MUDSKIPPER.getTime());
	}
	
	public static final void initUnder() {
		CoresManager.fastExecutor.schedule(new TimerTask() {
			@Override
			public void run() {
				try {
					initRefresh();
					World.sendWorldMessage(
							"<img=7><col=FF0000>News: A myserious figure has arrived at 'Underground'!",
							false);
					World.sendWorldMessage(
							"<img=7><col=FF0000>Speak with General Khazard to join the battle!",
							false);
					World.spawnNPC(14256, new WorldTile(2341, 9844, 0), -1,
							true, true);
					Logger.log("Lucien", "Underground: Raid initiated.");
				} catch (Throwable e) {
					Logger.handle(e);
				}
			}
		}, 0, Delay.UNDERGROUND.getTime());
	}
	
	public static final void initLegends() {
		CoresManager.fastExecutor.schedule(new TimerTask() {
			@Override
			public void run() {
				try {
					initRefresh();
					World.sendWorldMessage(
							"<img=7><col=FF0000>News: A myserious figure has arrived at 'Legends'!",
							false);
					World.sendWorldMessage(
							"<img=7><col=FF0000>Speak with General Khazard to join the battle!",
							false);
					World.spawnNPC(14256, new WorldTile(2778, 9336, 0), -1,
							true, true);
					Logger.log("Lucien", "Legends: Raid initiated.");
				} catch (Throwable e) {
					Logger.handle(e);
				}
			}
		}, 0, Delay.LEGENDS.getTime());
	}

	public static final void initRefresh() {
		for (NPC n : World.getNPCs()) {
			if (n == null || n.getId() != 14256)
				continue;
			n.sendDeath(n);
		}
		for (Player p : World.getPlayers()) {
			p.getMusicsManager().playMusic(361);
		}
		killEvents();
		Logger.log("Lucien", "Refresh task completed.");
	}
}
